<?php
namespace app\erp_meixingtiyu\model;

use think\Model;

class CourseLesson extends Model
{
    protected $table = 'athlon_course_lesson';
    protected $pk = 'lesson_id';

    public function clockIn()
    {
      return $this->hasMany(CourseLessonClockIn::class, 'lesson_id', 'lesson_id');
    }

    public function selectAllLessonsByCourseId($courseId)
    {
      return self::where('course_id', $courseId)->order('sort asc')->paginate(15);
    }

    public function createLesson($data)
    {
      return self::create($data);
    }

    public function updateLesson($data)
    {
      return self::update($data);
    }

    public function destroyLesson($lessonId)
    {
      return self::destroy($lessonId);
    }

    // 根据lesson_id获取info
    public static function getLessonById($lessonId)
    {
      return self::findOrEmpty($lessonId);
    }

    public function getLessonsByCourseId($courseId)
    {
      return self::where('course_id', $courseId)->select();
    }
}